/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nightonke.boommenusample.slice;

import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenu.Util;
import com.nightonke.boommenusample.BuilderManager;
import com.nightonke.boommenusample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.utils.Point;

public class CustomPositionAbilitySlice extends AbilitySlice {
    /**
     * onStart
     * @param intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_custom_position);

        initializeBmb1();
        initializeBmb2();
        initializeBmb3();
        initializeBmb4();
    }

    /**
     * initializeBmb1
     */
    private void initializeBmb1() {
        BoomMenuButton bmb = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb1);
        for (int i = 0; i < bmb.getButtonPlaceEnum().buttonNumber(); i++)
            bmb.addBuilder(BuilderManager.getHamButtonBuilder());

        float w05 = bmb.getHamWidth() / 2;
        float h05 = bmb.getHamHeight() / 2;

        float hm05 = bmb.getPieceHorizontalMargin() / 2;
        float vm05 = bmb.getPieceVerticalMargin() / 2;

        bmb.getCustomPiecePlacePositions().add(new Point(-w05 - hm05, -h05 - vm05));
        bmb.getCustomPiecePlacePositions().add(new Point(+w05 + hm05, -h05 - vm05));
        bmb.getCustomPiecePlacePositions().add(new Point(-w05 - hm05, +h05 + vm05));
        bmb.getCustomPiecePlacePositions().add(new Point(+w05 + hm05, +h05 + vm05));
        bmb.buildButton();
    }

    private void initializeBmb2() {
        BoomMenuButton bmb = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb2);
        for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++)
            bmb.addBuilder(BuilderManager.getSimpleCircleButtonBuilder());

        bmb.getCustomButtonPlacePositions().add(new Point(Util.dp2px(-80), Util.dp2px(-80)));
        bmb.getCustomButtonPlacePositions().add(new Point(0, 0));
        bmb.getCustomButtonPlacePositions().add(new Point(Util.dp2px(+80), Util.dp2px(+80)));
        bmb.buildButton();
    }

    private void initializeBmb3() {
        BoomMenuButton bmb = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb3);
        for (int i = 0; i < 12; i++)
            bmb.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilderWithDifferentPieceColor());

        float w = Util.dp2px(80);
        float h = Util.dp2px(96);
        float h05 = h / 2;
        float h15 = h * 1.5f;

        float hm = bmb.getButtonHorizontalMargin();
        float vm = bmb.getButtonVerticalMargin();
        float vm05 = vm / 2;
        float vm15 = vm * 1.5f;

        bmb.getCustomButtonPlacePositions().add(new Point(-w - hm, -h15 - vm15));
        bmb.getCustomButtonPlacePositions().add(new Point(      0, -h15 - vm15));
        bmb.getCustomButtonPlacePositions().add(new Point(+w + hm, -h15 - vm15));
        bmb.getCustomButtonPlacePositions().add(new Point(-w - hm, -h05 - vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(      0, -h05 - vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(+w + hm, -h05 - vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(-w - hm, +h05 + vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(      0, +h05 + vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(+w + hm, +h05 + vm05));
        bmb.getCustomButtonPlacePositions().add(new Point(-w - hm, +h15 + vm15));
        bmb.getCustomButtonPlacePositions().add(new Point(      0, +h15 + vm15));
        bmb.getCustomButtonPlacePositions().add(new Point(+w + hm, +h15 + vm15));
        bmb.buildButton();
    }

    private void initializeBmb4() {
        BoomMenuButton bmb = (BoomMenuButton) findComponentById(ResourceTable.Id_bmb4);
        for (int i = 0; i < 3; i++)
            bmb.addBuilder(BuilderManager.getTextInsideCircleButtonBuilder());

        bmb.getCustomPiecePlacePositions().add(new Point(Util.dp2px(+6), Util.dp2px(-6)));
        bmb.getCustomPiecePlacePositions().add(new Point(0, 0));
        bmb.getCustomPiecePlacePositions().add(new Point(Util.dp2px(-6), Util.dp2px(+6)));

        bmb.getCustomButtonPlacePositions().add(new Point(Util.dp2px(-80), Util.dp2px(-80)));
        bmb.getCustomButtonPlacePositions().add(new Point(0, 0));
        bmb.getCustomButtonPlacePositions().add(new Point(Util.dp2px(+80), Util.dp2px(+80)));
        bmb.buildButton();
    }

    /**
     * onActive
     */
    @Override
    public void onActive() {
        super.onActive();
    }

    /**
     * onForeground
     * @param intent
     */
    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
